﻿Ext
		.onReady(function() {
			Ext.QuickTips.init();
			Ext.form.Field.prototype.msgTarget = 'under';
			var classId ;
			var className;
			var classroomId;
			var classroomName;
			var teacherId;
			var teacherName;
			var weektimes;
		
			
		/*****************************************教室模块******************************************/	
			var classrooms = new Ext.data.Record.create( [ {
				name : 'id',
				type : 'int'
			},  {
				name : 'name',
				type : 'string'
			} ,{
				name : 'number',
				type : 'int'
			},{
				name : 'teachingbuilding.teachingbuilding_name',
				type : 'String'
			}
			]);
			var classroomsstore = new Ext.data.Store( {
				proxy : new Ext.data.HttpProxy( {
					url : '/schedule/queryClassroom'
				}),
				reader : new Ext.data.JsonReader( {
					totalProperty : 'totalProperty',
					root : 'root'
				}, classrooms),
				remoteSort : true
			});
			classroomsstore.load();
			var classroomsSm = new Ext.grid.CheckboxSelectionModel({singleSelect : true});
			var classroomsCols = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
			       classroomsSm, {
						header : '教室名称',
						dataIndex : 'name'
					}, {
						header : '教室人数',
						dataIndex : 'number'
					}, {
						header : '所属教学楼',
						dataIndex : 'teachingbuilding.teachingbuilding_name'
					}]);
			classroomsCols.defaultSortable = true;

			var classroomsGrid = new Ext.grid.GridPanel(
					{
						title : '教室信息列表',
						region : 'west',
						buttonAlign : "left",
						width : 250,
						height : 500,
						loadMask : true,
						store : classroomsstore,
						disableSelection : false,
						cm : classroomsCols,
						sm :classroomsSm,
						viewConfig : {
							forceFit : true
						},
						bbar : new Ext.PagingToolbar( {
							store : classroomsstore,
							pageSize : 15,// 页大小
							displayInfo : false,// 是否显示displayMsg
							displayMsg : "本页显示第{0}条到第{1}条的记录,一共{2}条",
							emptyMsg : "没有记录"// 如果没有记录，则显示该文本
						}),
						buttons:[{
							text:"添加教学计划",
							listeners :{
								 click : function(){
								  //alert(classroomId+"-"+teacherId+"-"+classId+"-"+courseId);
								  var flag = classroomId+"-"+teacherId+"-"+classId+"-"+courseId+"-"+weektimes;
								  if(classroomId==undefined){
								  	alert("请选择教室!");
								  	return false;
								  };
								  if(classId==undefined){
								  	alert("请选择班级!");
								  	return false;
								  };
								  if(teacherId==undefined){
								  	alert("请选择教师!");
								  	return false;
								  };
								  if(courseId==undefined){
								  	alert("请选择课程!");
								  	return false;
								  };
								  	var scheudle = Ext.Ajax.request({
										url : "/schedule/addSchedule?flag="+flag,
										method : "post",
										success : function(data) {//成功的返回
											var messagesplit = (data.responseText).split("@");
											alert(messagesplit[1]);
										}
									});
								 }
								}
						}],
						listeners:{
							"rowclick" : function(grid, rowIndex, e) {
								classroomId = grid.getSelectionModel().getSelections()[0].get("id");
								var classroom_teachingbuilding = grid.getSelectionModel().getSelections()[0].get("teachingbuilding.teachingbuilding_name");
								classroomName = classroom_teachingbuilding+"-"+grid.getSelectionModel().getSelections()[0].get("name");
								//var newwin = window.showModelessDialog("courseListByClassroom.jsp", classroom_id+","+classroom_teachingbuilding+"-"+classroom_name, "dialogTop:500px;dialogWidth:800px;dialogHeight:500px;location=no;resizable:yes; dialogLeft:300px;modal=yes");
								//var newwin = window.showModalDialog("courseListByClassroom.jsp", classroom_id+","+classroom_teachingbuilding+"-"+classroom_name, "dialogTop:100px;dialogWidth:1000px;dialogHeight:600px;location=no; dialogLeft:300px;modal=yes");
							}
						}
					});
			var classroomform = new Ext.form.FormPanel( {
				id : 'classroomform',
				width : 250,
				height : 500,
				hideBorders : true,
				labelWidth : 80,
				labelAlign : "right",
				items :classroomsGrid
			});
	/*****************************************教室模块完毕******************************************/
			
	/*****************************************课程模块******************************************/		
			var course = new Ext.data.Record.create( [ {
				name : 'id',
				type : 'int'
			}, {
				name : 'course.course_id',
				type : 'int'
			},{
				name : 'course.course_name',
				type : 'string'
			},{
				name : 'course.course_code',
				type : 'string'
			},{
				name : 'course.course_totaltime',
				type : 'string'
			},{
				name : 'course.course_week',
				type : 'string'
			}]);
			
			
			//var coursePanel = function(classId){
				var coursestore = new Ext.data.Store( {
					proxy : new Ext.data.HttpProxy( {
						url : "/schedule/queryClassRCourse?flag="+classId
					}),
					reader : new Ext.data.JsonReader( {
						totalProperty : 'totalProperty',
						root : 'root'
					}, course),
					remoteSort : true
				});
				coursestore.load();
				var courseSm = new Ext.grid.CheckboxSelectionModel({singleSelect : true});
				var courseCols = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
				           courseSm, {
							header : '课程编号',
							dataIndex : 'course.course_code'
						},{
							header : '课程名称',
							dataIndex : 'course.course_name'
						},{
							header : '总课时',
							dataIndex : 'course.course_totaltime'
						}]);
				courseCols.defaultSortable = true;
	
				var courseGrid = new Ext.grid.GridPanel(
						{
							title : '课程信息列表',
							region : 'center',
							buttonAlign : "left",
							width : 250,
							height : 460,
							loadMask : true,
							store : coursestore,
							disableSelection : false,
							cm : courseCols,
							sm :courseSm,
							viewConfig : {
								forceFit : true
							},
							bbar : new Ext.PagingToolbar( {
								store : coursestore,
								pageSize : 15,// 页大小
								displayInfo : false,// 是否显示displayMsg
								displayMsg : "本页显示第{0}条到第{1}条的记录,一共{2}条",
								emptyMsg : "没有记录"// 如果没有记录，则显示该文本
							}),
							listeners:{
								"rowclick" : function(grid, rowIndex, e) {
									courseId = grid.getSelectionModel().getSelections()[0].get("course.course_id");
									courseName = grid.getSelectionModel().getSelections()[0].get("course.course_name");
									weektimes = grid.getSelectionModel().getSelections()[0].get("course.course_totaltime")/grid.getSelectionModel().getSelections()[0].get("course.course_week");
									teacherform.render("foot2");
									teacherstore.proxy = new Ext.data.HttpProxy( {//传入参数
										url : "/schedule/queryTeacherRCourse?flag="+courseId
									});
									teacherstore.reload();//重新加载
									//var teachers_name = grid.getSelectionModel().getSelections()[0].get("teachers_name");
									//var newwin = window.showModelessDialog("courseListByTeacher.jsp", teachers_id+","+teachers_name, "dialogTop:500px;dialogWidth:800px;dialogHeight:500px;location=no;resizable:yes; dialogLeft:200px;modal=yes");
									//var newwin = window.showModalDialog("courseListByTeacher.jsp", teachers_id+","+teachers_name, "dialogTop:100px;dialogWidth:1000px;dialogHeight:600px;location=no; dialogLeft:300px;modal=yes");
								}
							}
						});
				var courseform = new Ext.form.FormPanel( {
					id : "courseform",
					//renderTo:"foot1",
					width : 250,
					height :460,
					hideBorders : true,
					labelWidth : 80,
					labelAlign : "right",
					items :courseGrid
				});
		/*****************************************课程模块完毕******************************************/		
		//	}
			/*****************************************教师模块******************************************/
			var teacher = new Ext.data.Record.create( [ {
				name : 'id',
				type : 'int'
			}, {
				name : 'teachers.teachers_id',
				type : 'int'
			},{
				name : 'teachers.teachers_name',
				type : 'string'
			},{
				name : 'teachers.teachers_code',
				type : 'string'
			},{
				name : 'teachers.teachers_zhichen',
				type : 'string'
			}]);
				var teacherstore = new Ext.data.Store( {
					proxy : new Ext.data.HttpProxy( {
						url : "/schedule/queryClassRCourse?flag="+classId
					}),
					reader : new Ext.data.JsonReader( {
						totalProperty : 'totalProperty',
						root : 'root'
					}, teacher),
					remoteSort : true
				});
				teacherstore.load();
				var teacherSm = new Ext.grid.CheckboxSelectionModel({singleSelect : true});
				var teacherCols = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
				           teacherSm, {
							header : '教师编号',
							dataIndex : 'teachers.teachers_code'
						},{
							header : '教师名称',
							dataIndex : 'teachers.teachers_name'
						},{
							header : '职称',
							dataIndex : 'teachers.teachers_zhichen'
						}]);
				teacherCols.defaultSortable = true;
	
				var teacherGrid = new Ext.grid.GridPanel(
						{
							title : '教师信息列表',
							region : 'center',
							buttonAlign : "left",
							width : 250,
							height : 460,
							loadMask : true,
							store : teacherstore,
							disableSelection : false,
							cm : teacherCols,
							sm :teacherSm,
							viewConfig : {
								forceFit : true
							},
							bbar : new Ext.PagingToolbar( {
								store : teacherstore,
								pageSize : 15,// 页大小
								displayInfo : false,// 是否显示displayMsg
								displayMsg : "本页显示第{0}条到第{1}条的记录,一共{2}条",
								emptyMsg : "没有记录"// 如果没有记录，则显示该文本
							}),
							listeners:{
								"rowclick" : function(grid, rowIndex, e) {//rowdblclick
									teacherId = grid.getSelectionModel().getSelections()[0].get("teachers.teachers_id");
									teacherName = grid.getSelectionModel().getSelections()[0].get("teachers.teachers_name");
									classroomform.render("foot4");
									classroomsstore.reload();
									//var newwin = window.showModelessDialog("courseListByTeacher.jsp", teachers_id+","+teachers_name, "dialogTop:500px;dialogWidth:800px;dialogHeight:500px;location=no;resizable:yes; dialogLeft:200px;modal=yes");
									//var newwin = window.showModalDialog("courseListByTeacher.jsp", teachers_id+","+teachers_name, "dialogTop:100px;dialogWidth:1000px;dialogHeight:600px;location=no; dialogLeft:300px;modal=yes");
								}
							}
						});
				var teacherform = new Ext.form.FormPanel( {
					id : "teacherform",
					//renderTo:"foot1",
					width : 250,
					height :460,
					hideBorders : true,
					labelWidth : 80,
					labelAlign : "right",
					items :teacherGrid
				});
			
			/*****************************************教师模块完毕******************************************/
			/*****************************************班级模块******************************************/
			var classes = new Ext.data.Record.create([{
				name : 'classes_id',
				type : 'int'
			}, {
				name : 'classes_name',
				type : 'string'
			},{
				name : 'classes_code',
				type : 'string'
			}]);
			
			var classesstore = new Ext.data.Store( {
				proxy : new Ext.data.HttpProxy( {
					url : '/schedule/queryClasses'
				}),
				reader : new Ext.data.JsonReader( {
					totalProperty : 'totalProperty',
					root : 'root'
				}, classes),
				remoteSort : true
			});
			classesstore.load();
			var classesSm = new Ext.grid.CheckboxSelectionModel({singleSelect : true});
			var classesCols = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
			           classesSm, {
						header : '班级名称',
						dataIndex : 'classes_name'
					},{
						header : '班级编号',
						dataIndex : 'classes_code'
					}]);
			classesCols.defaultSortable = true;

			var classesGrid = new Ext.grid.GridPanel(
					{
						title : '班级信息列表',
						region : 'center',
						buttonAlign : "left",
						width : 250,
						height : 460,
						loadMask : true,
						store : classesstore,
						disableSelection : false,
						cm : classesCols,
						sm :classesSm,
						viewConfig : {
							forceFit : true
						},
						bbar : new Ext.PagingToolbar( {
							store : classesstore,
							pageSize : 15,// 页大小
							displayInfo : false,// 是否显示displayMsg
							displayMsg : "本页显示第{0}条到第{1}条的记录,一共{2}条",
							emptyMsg : "没有记录"// 如果没有记录，则显示该文本
						}),
						listeners:{
							"rowclick" : function(grid, rowIndex, e) {
								classId = grid.getSelectionModel().getSelections()[0].get("classes_id");
								className = grid.getSelectionModel().getSelections()[0].get("classes_name");
								courseform.render("foot1");
								coursestore.proxy = new Ext.data.HttpProxy( {
									url : "/schedule/queryClassRCourse?flag="+classId
								});
								coursestore.reload();
								//coursePanel(classId);
								//var newwin = window.showModelessDialog("choiceCourse1.jsp", classes_id, "dialogTop:500px;dialogWidth:800px;dialogHeight:500px;location=no;resizable:yes; dialogLeft:100px;modal=yes");
							}
						}
					});
			
			var classesform = new Ext.form.FormPanel( {
				id : "classesform",
				width : 250,
				height : 460,
				renderTo:'foot3',
				hideBorders : true,
				labelWidth : 80,
				labelAlign : "right",
				items :classesGrid
			});
		/*****************************************班级模块完毕******************************************/
		/*****************************************按钮模块******************************************/
		
		});